package cn.xiangyuanpin.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class JdbcUtil {
    private static DruidDataSource druidDataSource;

    static{
        Properties properties=new Properties();
        InputStream resourceAsStream = JdbcUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
        try {
            properties.load(resourceAsStream);
            druidDataSource=(DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }




    public  static Connection  getConnection()  {
        Connection  coon= null;
        try {
            coon = druidDataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return coon;
    }
    public  static void  close(Connection connection) throws SQLException {
      if(connection!=null){
          connection.close();
      }
    }



}
